home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 January: Mac OS SDK / Dev.CD Jan 98 SDK1.toast / Development Kits (Disc 1) / Open Transport / Sample Code / NetFractal™ / ES stuff□ / ScreenTarget.cpp < prev    next >
Encoding:
Text File  |  1996-11-19  |  2.0 KB  |  101 lines  |  [TEXT/MPCC]

  1. //    ScreenTarget.cpp
  2.  
  3.  
  4. #include "ScreenTarget.h"
  5. #include <QDOffscreen.h>
  6.  
  7.  
  8. ScreenTarget::ScreenTarget(
  9.     WindowPtr window)
  10. {
  11.     UpdateFromWindow(window);
  12. }
  13.  
  14.  
  15. ScreenTarget::~ScreenTarget()
  16. {
  17. }
  18.  
  19.  
  20. void
  21. ScreenTarget::UpdateFromWindow(
  22.     WindowPtr window)
  23. {
  24.     Rect globalRect = window->portRect;
  25.     GrafPtr savePort;
  26.     GetPort(&savePort);
  27.     SetPort(window);
  28.     LocalToGlobal(&topLeft(globalRect));
  29.     LocalToGlobal(&botRight(globalRect));
  30.     GDHandle theDevice = GetMaxDevice(&globalRect);
  31.     PixMapHandle thePixMap = (*theDevice)->gdPMap;
  32.  
  33.     char *tba = GetPixBaseAddr(thePixMap);
  34.     rowBytes = (*thePixMap)->rowBytes&0x3fff;
  35.     int indenth = 8 - (globalRect.left&7); // ensure double alignment
  36.     tba += indenth+globalRect.left;
  37.     tba += globalRect.top*rowBytes;
  38.     width = ((globalRect.right-globalRect.left-indenth)&~7)/2;
  39.     height = (globalRect.bottom-globalRect.top)/2;
  40.     addRowBytes = rowBytes-(width*2);
  41.     baseAddr = tba;
  42.     SetPort(savePort);
  43. }
  44.  
  45.  
  46. void
  47. ScreenTarget::PutData(
  48.     const void *inPtr,
  49.     long inRowBytes,
  50.     long inWidth,
  51.     long inNumRows,
  52.     long destRow,
  53.     long destCol)
  54. {
  55.     const int cAddRowBytes = (inRowBytes-inWidth)>>2; // in longs
  56.     const long *srcPtr = (long *)inPtr;
  57.     const int cWidth = inWidth>>2; // num longs
  58.  
  59.     const int dAddRowBytes = (rowBytes-inWidth)>>2; // in doubles, two scan lines
  60.     double *dstPtr = (double *)baseAddr;
  61.     double *dstPtr2 = ((double*)dstPtr)+(rowBytes>>3);
  62.     double dBuf;
  63.     double *dBufP = 1+&dBuf;
  64.  
  65.     long initAdjust = (destRow*rowBytes>>2)+(destCol>>3);
  66.     dstPtr += initAdjust;
  67.     dstPtr2 += initAdjust;
  68.     
  69.     int h = inNumRows;
  70.  
  71.     srcPtr--; // adjust for pre-increment
  72.     dstPtr--;
  73.     dstPtr2--;
  74.  
  75.     while (--h >= 0) {
  76.         int v = cWidth;
  77.         while (--v >= 0) {
  78.             long l = *++srcPtr;
  79.             char *d = (char *)dBufP;
  80.             long l2 = l >> 8;
  81.             *--d = l;
  82.             *--d = l;
  83.             long l3 = l >> 16;
  84.             *--d = l2;
  85.             *--d = l2;
  86.             long l4 = l >> 24;
  87.             *--d = l3;
  88.             *--d = l3;
  89.             *--d = l4;
  90.             *--d = l4;
  91.             double dd = dBuf;
  92.             *++dstPtr = dd;
  93.             *++dstPtr2 = dd;
  94.         }
  95.         dstPtr += dAddRowBytes;
  96.         dstPtr2 += dAddRowBytes;
  97.         srcPtr += cAddRowBytes;
  98.     }
  99. }
  100.  
  101.